<template>
	<view>
		<uni-nav-bar title="诊断列表" backgroundColor="#fff" color="#000" statusBar="true" @clickLeft="back()"
			left-icon="arrowleft"></uni-nav-bar>
			
		<!-- <view class="tabControl">
			<view class="tab">
				<u-tabs :list="tabList" @click="click" :current="tabIndex" activeStyle='color: #0480FB'></u-tabs>
				<view class="line"></view>
			</view>
		</view> -->
		<view class="subsection">
			<scroll-view class="select-top-bar" :scroll-x="true">
				<view v-for="(item, index) in tabList" :key="index" @click="click(item)"
					class="select-top-bar-item" :class="{ 'selected': tabIndex == index }">
					<view class="top-bar-item-title">{{ item.name }}</view>
				</view>
			</scroll-view>
		</view>
		
		<view class="main">
			<view class="content">
				<scroll-view class="scrollView" scroll-y="true" @scrolltolower="handleScrolltolowerone()"
					:style="{height: setcollapseheight() + 'px'}">
					<view v-if="diagnosticList.length>0">
						<view class="contentItem" v-for="(item,index) in diagnosticList" :key="item.invitationId"
							@click="godetails(item)">
							<view class="header">
								<view class="serialnumber"></view>
								<view class="title">
									{{item.invitationTitle}}
								</view>
								<view class="img1" v-if="item.topFlag">
									<view class="line"></view>
									置顶
									<view class="san">
									</view>
								</view>
								<view class="img2" v-if="item.choicenessFlag">
									<view class="line"></view>
									精
								</view>
							</view>
							<view class="container">
								<view class="img">
									<image src="@/static/index-message/V.png"></image>
								</view>
								<view class="text">
									{{item.invitationContent}}
								</view>
							</view>
							<view class="container">
								<view class="img3">
									<image src="@/static/index-message/jingliren.png"></image>
								</view>
								<view class="text">
									问帖人：{{item.publisher.nickName}}
								</view>
							</view>
							<view class="container">
								<view class="img4">
									<image src="@/static/index-message/unit.png"></image>
								</view>
								<view class="text">
									问帖时间：{{item.createTime}}
								</view>
							</view>
							<view class="container">
								<view class="img4">
									<image src="@/static/index-message/liulanliang.png"></image>
								</view>
								<view class="text">
									浏览量：{{item.pageView}}
								</view>
							</view>
						</view>
					</view>
					<view v-if="diagnosticList.length==0">
						<view class="blank">
							<image src="@/static/blank.png" mode=""></image>
							<view class="nodata">
								暂无数据
							</view>
						</view>
					</view>
					<view class="bottom-ios-line">
					</view>
				</scroll-view>
			</view>
		</view>
		
		<bottomTabar></bottomTabar>
	</view>
</template>

<script>
	import bottomTabar from '../../components/bottom-tabar/index.vue'
	import navBar from '../../components/nav-bar/index.vue'
	import search from '../../components/search/index.vue'
	import Api from '@/api/socialized-servce/specialist-consultation/expert-module/diagnostic-list/index.js'
	export default {
		components: {
			bottomTabar,
			navBar,
			search
		},
		data() {
			return {
				tabList: [],
				tabSwitch: '',
				tabIndex: 0,
				invitationTypeId: '',
				diagnosticList: [],
				page: 1,
				size: 10,
				total: 0
			}
		},
		mounted() {
			this.setcollapseheight()
		},
		async created() {
			await this.getPostClassification()
			await this.getDiagnosticList()
		},
		methods: {
			async getPostClassification() {
				let params = {
					name: '',
					serviceProviderNo: uni.getStorageSync('serviceProviderNo')
				}
				let res = await Api.queryPostVariety(params)

				if (res.code == 200) {
					this.tabList = res.data
					this.tabList.forEach((el,index) =>{
						el.id = index
					})
					let id = uni.getStorageSync('specialistConsultationInvitationTypeId')
					if(id) {
						this.invitationTypeId = id
						this.tabSwitch = res.data.filter(el => el.invitationTypeId === id)[0].name
						this.tabIndex = res.data.filter(el => el.invitationTypeId === id)[0].id
					} else {
						this.invitationTypeId = res.data[0].invitationTypeId
						this.tabSwitch = res.data[0].name
						this.tabIndex = 0
					}
				}

			},
			async getDiagnosticList() {
				let params = {
					page: this.page,
					size: this.size,
					condition: {
						invitationTypeId: this.invitationTypeId,
						serviceProviderNo: uni.getStorageSync('serviceProviderNo')
					}

				}
				let res = await Api.queryPageDiagnostic(params)

				if (res.code == 200) {
					let arr = res.data.content
					this.total = res.data.totalElements
					this.diagnosticList = [...this.diagnosticList, ...arr]
				}
			},
			click(item) {
				this.tabIndex = item.id
				this.tabSwitch = item.name
				this.invitationTypeId = item.invitationTypeId
				uni.setStorageSync('specialistConsultationInvitationTypeId',item.invitationTypeId)
				this.diagnosticList = []
				this.page = 1
				this.getDiagnosticList()
			},
			setcollapseheight() {
				let topheightone = uni.upx2px(260)
				let newheight = this.customBar + topheightone
				let winHeight = 0
				uni.getSystemInfo({
					success: function(res) {
						winHeight = res.windowHeight
					}
				});
				winHeight = parseInt(winHeight) - newheight
				// #ifndef H5
				winHeight = winHeight

				// #endif
				return winHeight
			},
			godetails(e) {
				uni.navigateTo({
					url: `/subPage1/socialized-service/specialist-consultation/expert-module/diagnostic-list/invitation-details/invitation-details?id=${e.invitationId}`
				})
			},
			shareSearchList(e, x) {
				this.diagnosticList = e
				this.page = x
			},
			handleScrolltolowerone() {
				if(this.total>this.diagnosticList.length) {
					this.page = this.page + 1
					this.getDiagnosticList()
				} else {
					console.log('触底');
					return
				}
			},
			back() {
				uni.switchTab({
					url: '/pages/socialized-service/selection-system/selection-system'
				})
			},
			onPullDownRefresh() {
				console.log('下拉');
				this.page = 1
				this.diagnosticList = []
				this.getDiagnosticList()
				setTimeout(function() {
					uni.stopPullDownRefresh()
				}, 1000)
			},
		}
	}
</script>

<style lang="scss" scoped>
	.tabControl {
		width: 100%;
		top: 136rpx;
		z-index: 99999;
		background-color: #F5F6FA;

		.tab {
			position: relative;
			.line {
				position: absolute;
				bottom: -2rpx;
				width: 100%;
				border-bottom: 2rpx solid #C9E4FF;
				z-index: 6;
			}
		}
		::v-deep .u-tabs__wrapper__nav__item {
			width: 25%;
		}
		
		::v-deep .u-tabs__wrapper__nav__line {
			position: absolute;
			z-index: 9999!important;
			height: 2rpx!important;
			width: 25%!important;
			bottom: 0!important;
			background-color: #0e7ae9!important;
			left: -10%;
		}
	}
	
	.search {
		z-index: 9999;
	}

	.main {
		width: 100%;
		background: #F5F6FA;

		.content {
			position: relative;
			background: #F5F6FA;

			.blank {
				position: absolute;
				top: 50%;
				left: 50%;
				transform: translateY(-50%) translateX(-50%);
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;

				image {
					width: 200rpx;
					height: 200rpx;
				}

				.nodata {
					margin-top: 20rpx;
				}
			}

			.contentItem {
				position: relative;
				margin: 0 40rpx;
				margin-top: 16rpx;
				background-color: #FFFFFF;
				padding: 36rpx 12rpx 40rpx 12rpx;
				box-shadow: 0rpx 0rpx 12rpx 2rpx rgba(0, 0, 0, 0.05);
				border-radius: 16rpx 16rpx 16rpx 16rpx;

				.header {
					display: flex;
					justify-content: space-between;
					position: relative;

					.serialnumber {
						position: absolute;
						top: 8rpx;
						left: 0;
						width: 10rpx;
						height: 28rpx;
						background-color: #91743E;
					}

					.title {
						padding-left: 24rpx;
						font-size: 32rpx;
						font-weight: 500;
						color: #91743E;
						width: 70%;
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
					}
					
					.img1,.img2 {
						position: relative;
						top: -26rpx;
						width: 60rpx;
						height: 60rpx;
						text-align: center;
						color: #fff;
						background-color: #fa9f03;
						.line {
							position: absolute;
							top: -10rpx;
							width: 60rpx;
							height: 4rpx;
							background-color: red;
							border-radius: 6rpx;
							background-color: #fa9f03;
						}
						.san {
							position: absolute;
							top: 5rpx;
							border: 30rpx solid red;
							border-color: transparent transparent #fff transparent;
						}
					}
					.img2 {
						background-color: #ff7072;
						border-radius: 0 0 10rpx 10rpx;
						.line {
							background-color: #ff7072;
						}
					}
				}

				.container {
					display: flex;
					align-items: center;
					margin-left: 32rpx;
					margin-right: 10rpx;
					margin-top: 30rpx;
					font-size: 28rpx;
					font-family: Source Han Sans CN-Regular, Source Han Sans CN;
					font-weight: 400;
					color: #272727;
					
					.img {
						width: 35rpx;
						height: 30rpx;
					
						image {
							position: relative;
							z-index: 999;
							width: 35rpx;
							height: 30rpx;
						}
					}
					.img3 {
						width: 30rpx;
						height: 30rpx;
					
						image {
							position: relative;
							z-index: 999;
							width: 27rpx;
							height: 35rpx;
						}
					}
					.img4 {
						width: 35rpx;
						height: 26rpx;
					
						image {
							position: relative;
							z-index: 999;
							width: 35rpx;
							height: 26rpx;
						}
					}

					.text {
						padding-left: 24rpx;
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
					}
				}

				.contentbaseline {
					margin-top: 8rpx;
					border: 1px solid #DBEDFF;
				}

				.footer {
					margin-top: 16rpx;
					margin-left: 48rpx;
					font-size: 26rpx;
					font-weight: 400;
					color: #808080;

					.oneline {
						display: flex;
						flex-wrap: nowrap;

						.name {
							width: 197rpx;
							overflow: hidden;
							text-overflow: ellipsis;
							white-space: nowrap;
						}

						.time {
							margin-left: 30rpx;
						}
					}

					.twoline {
						margin-top: 16rpx;
					}
				}
			}
		}
	}
		
	.subsection {
		padding: 0 32rpx;
		margin: 20rpx 0;

		.select-top-bar {
			width: 100%;
			justify-content: space-around;
			white-space: nowrap;
			display: flex;
			flex-direction: row;
			flex-wrap: nowrap;
			align-items: center;

			.select-top-bar-item {
				display: inline-block;
				margin-right: 20rpx;
				padding-bottom: 12rpx;
				min-width: 162rpx;
				height: 60rpx;
				font-size: 30rpx;

				&.selected {
					border-bottom: 4rpx solid #0e7ae9;
				}

				&:last-child {
					margin-right: 0;
				}

				.top-bar-item-title {
					min-width: 162rpx;
					height: 60rpx;
					line-height: 60rpx;
					text-align: center;
					padding: 0 10px;
				}
			}
		}
	}
</style>